import { ClassProxy } from "../../core/ClassProxy";
import { CacheManager } from "../../manager/CacheManager";
import ByteArray = require("bytearray-node")
type int = number;
//class ResourceInfo
    
    export  class ResourceInfo extends ClassProxy
    {
        constructor(arg1: Object=null)
        {
            
            super();if (arg1) 
            {
                this.type = arg1.type;
                this.name = arg1.name;
                this.time = arg1.time;
                this.path = arg1.path + "?v=" + arg1.time;
            }
            return;
        }

        /* internal  */writeCacheBytes(arg1: ByteArray): void
        {
            this._loadCacheBytes = arg1;
            return;
        }

        public get bytesDisposeTime(): number
        {
            return this._bytesDisposeTime;
        }

        
        {
            ResourceInfo.resCount = 0;
        }

        public resetDisposeTime(): void
        {
            this._bytesDisposeTime = flash.utils.getTimer() + ResourceInfo.ReleaseByteTime;
            return;
        }

        public get soPath(): string
        {
            var loc1=0;
            if (this._soPath == null) 
            {
                if (this.loaclPath) 
                {
                    loc1 = this.loaclPath.lastIndexOf("?");
                    if (loc1 > -1) 
                    {
                        this._soPath = this.loaclPath.slice(0, loc1);
                    }
                    else 
                    {
                        this._soPath = this.loaclPath;
                    }
                }
                else 
                {
                    this._soPath = "";
                }
            }
            return this._soPath;
        }

        public get isDispose(): Boolean
        {
            return this._isDispose;
        }

        public set data(arg1: Object)
        {
            this._data = arg1;
            this._isDispose = false;
            return;
        }

        public addReference(): void
        {
            var loc1;
            var loc2=((loc1 = this)._referenceCount + 1);
            loc1._referenceCount = loc2;
            return;
        }

        public removeReference(): void
        {
            var loc1;
            var loc2=((loc1 = this)._referenceCount - 1);
            loc1._referenceCount = loc2;
            return;
        }

        public dispose(): void
        {
            this._isDispose = true;
            this._data = null;
            this._referenceCount = 0;
            this.isLoaded = false;
            this.isLoading = false;
            this.extData = null;
            if (this.loaderInfo && this.loaderInfo.loader) 
            {
                this.unload(this.loaderInfo);
                this.loaderInfo = null;
            }
            return;
        }

        protected unload(arg1: Object /* flash.display.LoaderInfo */): void
        {
            try 
            {
                arg1.loader.close();
            }
            catch (e)
            {
            };
            arg1.loader.unload();
            return;
        }

        public isLoadedByteArray(): Boolean
        {
            if (this._loadCacheBytes) 
            {
                return true;
            }
            return false;
        }

        public get cacheBytes(): ByteArray
        {
            if (this._loadCacheBytes) 
            {
                return this._loadCacheBytes;
            }
            if (this.loaderInfo) 
            {
                this.writeCacheBytes(this.loaderInfo.bytes);
            }
            else 
            {
                this._loadCacheBytes = CacheManager.instance.readObject(this.name, this.time, this.soPath) as ByteArray;
            }
            return this._loadCacheBytes;
        }

        public set cacheBytes(arg1: ByteArray)
        {
            this.writeCacheBytes(arg1);
            ResourceInfo.resCount = ResourceInfo.resCount + this._loadCacheBytes.length;
            CacheManager.instance.writeObject(this.name, this.time, arg1, this.soPath);
            return;
        }

        public clearCacheBytes(): void
        {
            if (this._loadCacheBytes) 
            {
                this._loadCacheBytes = null;
            }
            return;
        }

        public static /* const */ReleaseByteTime: number=3 * 60 * 1000;

        protected /* var */loaderInfo: Object /* flash.display.LoaderInfo */;

        public /* var */name: string;

        public /* var */time: string;

        public /* var */path: string;

        public /* var */type: string;

        private /* var */_data: Object;

        public /* var */extData: Object;

        public /* var */isHasLoaded: Boolean=false;

        public /* var */isLoaded: Boolean;

        public /* var */isLoading: Boolean=false;

        public /* var */isAddToPreLoad: Boolean=false;

        public /* var */isPreLoading: Boolean=false;

        private /* var */_loadCacheBytes: ByteArray=null;

        private /* var */_referenceCount: int=0;

        private /* var */_isDispose: Boolean=false;

        private /* var */_bytesDisposeTime: number=0;

        public /* var */loaclPath: string;

        public static /* var */resCount: number=0;

        private /* var */_soPath: string=null;
    }
